home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmLoan
- Caption = "Analysis Of A Loan"
- ClientHeight = 4005
- ClientLeft = 510
- ClientTop = 1845
- ClientWidth = 9000
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 4005
- ScaleWidth = 9000
- Begin VB.CommandButton cmdQuit
- Caption = "Quit"
- Height = 375
- Left = 960
- TabIndex = 9
- Top = 3360
- Width = 1575
- End
- Begin VB.CommandButton cmdAmort
- Caption = "Display Amortization Schedule"
- Height = 375
- Left = 120
- TabIndex = 8
- Top = 2760
- Width = 3255
- End
- Begin VB.CommandButton cmdRateTable
- Caption = "Display Interest Rate Change Table"
- Height = 375
- Left = 120
- TabIndex = 7
- Top = 2160
- Width = 3255
- End
- Begin VB.CommandButton cmdPayment
- Caption = "Calculate Monthly Payment"
- Height = 375
- Left = 120
- TabIndex = 6
- Top = 1560
- Width = 3255
- End
- Begin VB.PictureBox picDisp
- Height = 3735
- Left = 3600
- ScaleHeight = 3675
- ScaleWidth = 5235
- TabIndex = 10
- Top = 120
- Width = 5292
- End
- Begin VB.TextBox txtYrs
- Height = 285
- Left = 2160
- TabIndex = 5
- Top = 1080
- Width = 1215
- End
- Begin VB.TextBox txtApr
- Height = 285
- Left = 2160
- TabIndex = 3
- Top = 600
- Width = 1215
- End
- Begin VB.TextBox txtAmt
- Height = 285
- Left = 2160
- TabIndex = 1
- Top = 120
- Width = 1215
- End
- Begin VB.Label lblYrs
- Alignment = 1 'Right Justify
- Caption = "Number Of Loan Years:"
- Height = 255
- Left = 0
- TabIndex = 4
- Top = 1080
- Width = 2055
- End
- Begin VB.Label lblApr
- Alignment = 1 'Right Justify
- Caption = "Interest APR:"
- Height = 255
- Left = 0
- TabIndex = 2
- Top = 600
- Width = 2055
- End
- Begin VB.Label lblAmt
- Alignment = 1 'Right Justify
- Caption = "Amount Of Loan:"
- Height = 255
- Left = 0
- TabIndex = 0
- Top = 120
- Width = 2055
- End
- Attribute VB_Name = "frmLoan"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private Function Balance(mPayment As Single, prin As Single, mRate As Single) As Single
- Dim newBal As Single
- 'Compute balance at end of month
- newBal = (1 + mRate) * prin
- If newBal <= mPayment Then
- mPayment = newBal
- Balance = 0
- Else
- Balance = newBal - mPayment
- End If
- End Function
- Private Sub cmdAmort_Click()
- Dim principal As Single 'Amount of loan
- Dim yearlyRate As Single 'Annual rate of interest
- Dim numMonths As Integer 'Number of months to repay loan
- Call InputData(principal, yearlyRate, numMonths)
- Call ShowAmortSched(principal, yearlyRate, numMonths)
- End Sub
- Private Sub cmdPayment_Click()
- Dim principal As Single 'Amount of loan
- Dim yearlyRate As Single 'Annual rate of interest
- Dim numMonths As Integer 'Number of months to repay loan
- Call InputData(principal, yearlyRate, numMonths)
- Call ShowPayment(principal, yearlyRate, numMonths)
- End Sub
- Private Sub cmdQuit_Click()
- End
- End Sub
- Private Sub cmdRateTable_Click()
- Dim principal As Single 'Amount of loan
- Dim yearlyRate As Single 'Annual rate of interest
- Dim numMonths As Integer 'Number of months to repay loan
- Call InputData(principal, yearlyRate, numMonths)
- Call ShowInterestChanges(principal, yearlyRate, numMonths)
- End Sub
- Private Sub InputData(prin As Single, yearlyRate As Single, numMs As Integer)
- Dim percentageRate As Single, numYears As Integer
- 'Input the loan amount, yearly rate of interest, and duration
- prin = Val(txtAmt.Text)
- percentageRate = Val(txtApr.Text)
- numYears = Val(txtYrs.Text)
- yearlyRate = percentageRate / 100
- numMs = numYears * 12
- End Sub
- Private Function Payment(prin As Single, mRate As Single, numMs As Integer) As Single
- Dim payEst As Single
- If numMs = 0 Then
- payEst = prin
- ElseIf mRate = 0 Then
- payEst = prin / numMs
- Else
- payEst = prin * mRate / (1 - (1 + mRate) ^ (-numMs))
- End If
- If payEst <> Round(payEst, 2) Then
- Payment = Round(payEst + 0.005, 2) 'round up to nearest cent
- End If
- End Function
- Private Sub ShowAmortSched(prin As Single, yearlyRate As Single, numMs As Integer)
- Dim msg As String, startMonth As Integer, mRate As Single
- Dim monthlyPayment As Single, totalInterest As Single
- Dim yearInterest As Single, oldBalance As Single
- Dim monthNum As Integer, newBalance As Single
- Dim principalPaid As Single, interestPaid As Single
- Dim reducPrin As Single, loanYears As Integer
- 'Display amortization schedule
- msg = "Please enter year (1-" & Str(numMs / 12)
- msg = msg & ") for which amorization is to be shown:"
- startMonth = 12 * Val(InputBox(msg)) - 11
- picDisp.Cls
- picDisp.Print "", "Amount Paid ",
- picDisp.Print "Amount Paid", "Balance at"
- picDisp.Print "Month", "for Principal",
- picDisp.Print "for Interest", "End of Month"
- mRate = yearlyRate / 12 'monthly rate
- monthlyPayment = Payment(prin, mRate, numMs)
- totalInterest = 0
- yearInterest = 0
- oldBalance = prin
- For monthNum = 1 To numMs
- newBalance = Balance(monthlyPayment, oldBalance, mRate)
- principalPaid = oldBalance - newBalance
- interestPaid = monthlyPayment - principalPaid
- totalInterest = totalInterest + interestPaid
- If (monthNum >= startMonth) And (monthNum <= startMonth + 11) Then
- picDisp.Print Tab(2); FormatNumber(monthNum, 0),
- picDisp.Print FormatCurrency(principalPaid),
- picDisp.Print FormatCurrency(interestPaid),
- picDisp.Print FormatCurrency(newBalance)
- yearInterest = yearInterest + interestPaid
- End If
- oldBalance = newBalance
- Next monthNum
- reducPrin = 12 * monthlyPayment - yearInterest
- loanYears = numMs / 12
- picDisp.Print
- picDisp.Print "Reduction in principal",
- picDisp.Print FormatCurrency(reducPrin)
- picDisp.Print "Interest paid", ,
- picDisp.Print FormatCurrency(yearInterest)
- picDisp.Print "Total interest over"; loanYears; "years",
- picDisp.Print FormatCurrency(totalInterest)
- End Sub
- Private Sub ShowInterestChanges(prin As Single, yearlyRate As Single, numMs As Integer)
- Dim newRate As Single, mRate As Single, py As Single
- Dim pymnt As String
- 'Display affect of interest changes
- picDisp.Cls
- picDisp.Print , "Annual"
- picDisp.Print , "Interest rate", "Monthly Payment"
- newRate = yearlyRate - 0.01
- mRate = newRate / 12 'monthly rate
- py = Payment(prin, mRate, numMs)
- pymnt = FormatCurrency(py)
- picDisp.Print , FormatPercent(newRate, 3), pymnt
- newRate = newRate + 0.00125
- Loop Until newRate > yearlyRate + 0.01
- End Sub
- Private Sub ShowPayment(prin As Single, yearlyRate As Single, numMs As Integer)
- Dim mRate As Single, prn As String, apr As String
- Dim yrs As String, pay As Single, pymnt As String
- 'Display monthly payment amount
- mRate = yearlyRate / 12 'monthly rate
- prn = FormatCurrency(prin)
- apr = FormatNumber(yearlyRate * 100)
- yrs = FormatNumber(numMs / 12, 0)
- pay = Payment(prin, mRate, numMs)
- pymnt = FormatCurrency(pay)
- picDisp.Cls
- picDisp.Print "The monthly payment for a " & prn & " loan at "
- picDisp.Print apr & "% annual rate of interest for ";
- picDisp.Print yrs & " years is " & pymnt
- End Sub
-